package com.sky.controller.admin;


import com.sky.result.Result;
import com.sky.utils.AliOSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
@Slf4j
@Api(tags = "文件上传接口")
public class UploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;

    /**
     * 文件上传下载
     * @param file
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "文件上传下载接口")
    @PostMapping("/admin/common/upload")
    public Result upload(MultipartFile file) throws IOException {
//        try {
//            String uploadFileName = image.getOriginalFilename();
//            log.info("[ 文件上传 ]: img{}", uploadFileName);
////            uploadFileName = UUID.randomUUID() + uploadFileName.substring(uploadFileName.lastIndexOf("."));
//
//
//            File file = new File("D:\\00_JavaWeb课程\\fileupLoadTest", uploadFileName);
//            image.transferTo(file);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        String url = aliOSSUtils.upload(file);
        return Result.success(url);
    }
}
